Table of Contents
1. Org Mode (01) - 撰写博客
Org Mode - Your life in plain text 可以做很多事情, 撰写博客也是其拿手好戏之一
借助 Org Mode 导出 HTML 的强大功能, 配合一定的格式设置, 一个简洁美观的博客就诞生了
Emacs Hacker 王勇在其博客文章 谈研发人员怎么专注 中提到一条法则
- 新闻获取的专注: 除了看书查手册以外, 研发人员也需要上网了解业界动态, 我推荐的方式是 ’用最少数量’的新闻网站和博客去了解最新技术, 我发现很多研发人员, 每天去看国内外大事和各种新闻网站杜撰的标题党新闻, 缺少社会经验和定力的年轻人最容易受这些负面的新闻影响心情, 或者把新闻当谈资, 我想的说是, 很多远在天边的人都和我们没关系, 我们每天要做的就是专注提升自己, 关心身边的人和真正的朋友。 心态一旦被各种猎奇信息干扰, 就很难保持对思考的专注。 回到标题, 我常年只看 solidot.org, 对于 IT 大事足够了, 最新的技术会订阅一些技术博客和每天浏览一次 Twitter 就好了
对于博客的基本要求: 简洁美观、 提供订阅
2. 配置 Org Mode 写博客的工作流
2.1. ox-html
(use-package ox-html
:after ox
:config
(setq org-export-global-macros
'(("timestamp" . "@@html:<span class=\"timestamp\">[$1]</span>@@")))
(setq org-html-preamble t)
(setq org-html-preamble-format
'(("en" "<a href=\"/index.html\" class=\"button\">Home</a>
<a href=\"/posts/index.html\" class=\"button\">Posts</a>
<a href=\"/about.html\" class=\"button\">About</a>
<a href=\"/rss.xml\" class=\"button\">RSS</a>
<hr>")))
(setq org-html-postamble t)
(setq org-html-postamble-format
'(("en" "<hr><div class=\"info\"> <span class=\"created\">Created with %c on Arch Linux</span>
<span class=\"updated\">Updated: %d</span> </div>")))
(setq org-html-head-include-default-style nil)
(setq org-html-head
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style.css\" />
<script src=\"js/copy.js\"></script> "))
2.2. ox-rss
借助 ox-rss 可为博客提供技术订阅
(add-to-list 'load-path "~/.emacs.d/site-lisp/ox-rss/")
(require 'ox-rss)
(defun posts-rss-feed (title list)
"Generate a sitemap of posts that is exported as a RSS feed.
TITLE is the title of the RSS feed. LIST is an internal
representation for the files to include. PROJECT is the current
project."
(concat
"#+TITLE: " title "\n\n"
(org-list-to-subtree list)))
(defun format-posts-rss-feed-entry (entry _style project)
"Format ENTRY for the posts RSS feed in PROJECT."
(let* (
(title (org-publish-find-title entry project))
(link (concat "posts/" (file-name-sans-extension entry) ".html"))
(pubdate (format-time-string (car org-time-stamp-formats)
(org-publish-find-date entry project))))
(message pubdate)
(format "%s
:properties:
:rss_permalink: %s
:pubdate: %s
:end:\n"
title
link
pubdate)))
(defun publish-posts-rss-feed (plist filename dir)
"Publish PLIST to RSS when FILENAME is rss.org.
DIR is the location of the output."
(if (equal "rss.org" (file-name-nondirectory filename))
(org-rss-publish-to-rss plist filename dir)))
2.3. ox-publish
(use-package ox-publish
:after ox
:config
;; https://git.sr.ht/~taingram/taingram.org/tree/master/item/publish.el
(defun taingram--sitemap-dated-entry-format (entry style project)
"Sitemap PROJECT ENTRY STYLE format that includes date."
(let ((filename (org-publish-find-title entry project)))
(if (= (length filename) 0)
(format "*%s*" entry)
(format "{{{timestamp(%s)}}} [[file:%s][%s]]"
(format-time-string "%Y-%m-%d"
(org-publish-find-date entry project))
entry
filename))))
(setq org-publish-project-alist
`(("site"
:base-directory "~/org/docs/blog/"
:base-extension "org"
:recursive nil
:publishing-directory "~/pages/"
:publishing-function org-html-publish-to-html)
("posts"
:base-directory "~/org/docs/blog/posts/"
:base-extension "org"
:exclude "rss.org"
:publishing-directory "~/pages/posts/"
:publishing-function org-html-publish-to-html
:with-author t
:auto-sitemap t
:sitemap-filename "index.org"
:sitemap-title "posts"
:sitemap-sort-files anti-chronologically
:sitemap-format-entry taingram--sitemap-dated-entry-format)
("static"
:base-directory "~/org/docs/blog/static/"
:base-extension "css\\|js\\|txt\\|jpg\\|gif\\|png"
:recursive t
:publishing-directory "~/pages/"
:publishing-function org-publish-attachment)
("rss"
:publishing-directory "~/pages/"
:base-directory "~/org/docs/blog/posts"
:base-extension "org"
:exclude "index.org"
:publishing-function publish-posts-rss-feed
:rss-extension "xml"
:html-link-home "https://mawen.codeberg.page/"
:html-link-use-abs-url t
:html-link-org-files-as-html t
:auto-sitemap t
:sitemap-function posts-rss-feed
:sitemap-title "mawen.codeberg.page"
:sitemap-filename "rss.org"
:sitemap-style list
:sitemap-sort-files anti-chronologically
:sitemap-format-entry format-posts-rss-feed-entry)
("personal-website" :components ("site" "posts" "static" "rss")))))